import grpc from 'grpc';

const PROTO_PATH = __dirname + '/../protos/userService.proto';
const service = grpc.load(PROTO_PATH).soa.service;
const client = new service.userService("localhost:3000", grpc.credentials.createInsecure());

const run = async (param) => {
  return new Promise((resolve, reject) => {
    client.getUserById(param, (err, response) => {
      if (err) {
        return reject(err);
      }
      resolve(response);
    });
  })
}


const main = async () => {
  console.log('start!');
  const start = new Date().getTime();
  for (let i = 0; i < 10000; i++) {
    const res = await run({userId: i});
    console.log(res);
  }
  console.log(`done! 10000 requests consts ${new Date().getTime() - start} ms!`);
}

main();